package com.test.daily.leetcode.y2022.m07.day0705.v04;

import java.util.Stack;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/5 下午 01:29
 * @version: 1.0
 */
public class Solution {


    public static class MyQueue{
        Stack<Integer> popStack;
        Stack<Integer> pushStack;
        public MyQueue(){
            this.popStack = new Stack<>();
            this.pushStack = new Stack<>();
        }
        public int peek(){
            pushStackToPopStack();
            return this.popStack.peek();
        }
        public void push(int data){
          pushStackToPopStack();
          this.pushStack.push(data);
        }
        public void pushStackToPopStack(){
            if(popStack.isEmpty()){
                while(!pushStack.isEmpty()){
                    popStack.push(pushStack.pop());
                }
            }
        }
        public int pop(){
            if(popStack.isEmpty() && pushStack.isEmpty()){
                throw new RuntimeException("stack is empty.");
            }
            pushStackToPopStack();
            return popStack.pop();
        }
    }
}
